package com.xpec.c4.service.module.datacenter.player;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.xpec.c4.game.datamanager.BaseDataInfo;
import com.xpec.c4.game.datamanager.DataRequestInfo;
import com.xpec.c4.game.datamanager.agent.PlayerData;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.annotations.MessageType;
import com.xpec.c4.service.contexts.Contexts;
import com.xpec.c4.service.module.datacenter.DataCenterModule;


/**
 * 
 * @author yangbingyan
 *
 */
public class PlayerDataProcess{


	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(PlayerDataProcess.class);
	
	@MessageType(typeCode =  MessageTypes.GET_PLAYER_LIST_BY_GUID)
	public void getPlayerListByGuid(DataRequestInfo objInfo){
		BaseDataInfo info = (BaseDataInfo)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		PlayerDataManager result = ((DataCenterModule)Contexts.getModule()).getPlayerDataManager();
		if(result != null){
			result.getPlayerListByGuid(info, srcModuleID);
		}
	}
	
	@MessageType(typeCode = MessageTypes.UPDATE_PLAYER_INFO)
	public void updatePlayerInfo(DataRequestInfo objInfo) {
		BaseDataInfo info = (BaseDataInfo) objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		PlayerDataManager result = ((DataCenterModule) Contexts.getModule()).getPlayerDataManager();
		if (result != null) {
			result.updateData(info, srcModuleID);
		}
	}

	@MessageType(typeCode = MessageTypes.UPDATE_PLAYER_MONEY)
	public void updatePlayerMoney(DataRequestInfo objInfo) {
		BaseDataInfo info = (BaseDataInfo) objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		DataCenterModule dcm = (DataCenterModule) Contexts.getModule();

		PlayerDataManager result = dcm.getPlayerDataManager();
		if (result != null) {
			result.updateMoney(dcm, info, srcModuleID);
		}
	}

	@MessageType(typeCode = MessageTypes.UPDATE_PLAYER_ITEM)
	public void updatePlayerItem(DataRequestInfo objInfo) {
		BaseDataInfo info = (BaseDataInfo) objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		DataCenterModule dcm = (DataCenterModule) Contexts.getModule();

		PlayerDataManager result = dcm.getPlayerDataManager();
		if (result != null) {
			result.updateItem(dcm, info, srcModuleID);
		}
	}
	
	
	@MessageType(typeCode = MessageTypes.UPDATE_PLAYER_MONEY_ITEM)
	public void updatePlayerMoneyItem(DataRequestInfo objInfo) {
		BaseDataInfo info = (BaseDataInfo) objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		DataCenterModule dcm = (DataCenterModule) Contexts.getModule();

		PlayerDataManager result = dcm.getPlayerDataManager();
		if (result != null) {
			result.updateMoneyItem(dcm, info, srcModuleID);
		}
	}

	@MessageType(typeCode = MessageTypes.QUERY_PLAYER_INFO_BY_GUID)
	public void queryPlayerInfo(DataRequestInfo objInfo){
		BaseDataInfo info = (BaseDataInfo)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		PlayerDataManager result = ((DataCenterModule)Contexts.getModule()).getPlayerDataManager();
		if(result != null){
			result.readData(info,	srcModuleID);
		}
	}
	
	@MessageType(typeCode = MessageTypes.CREATE_PLAYER_INFO)
	public void createPlayerInfo(DataRequestInfo objInfo){
		PlayerData info = (PlayerData)objInfo.getDataInfo();
		String srcModuleID = objInfo.getModuleID();
		PlayerDataManager result = ((DataCenterModule)Contexts.getModule()).getPlayerDataManager();
		if(result != null){
			result.createData(info, srcModuleID);
		}
	}
	
}
